function RequestTopics() {
    var prefs = new gadgets.Prefs();
    document.getElementById("link_home").innerHTML =
	"<a href=\"" + CalculateSiteURL("/library") +
	"\" target=\"_top\">Library Home</a>";
    var label = clean_label(prefs.getString("label"));
    var query = label ? ('?q=' + label) : ''
    RequestLibraryData('topics' + query, ProcessTopics);
}

function ProcessTopics(results, library_url, terms) {
    results.sort(LabelSorter);
    var url_base = CalculateSiteURL("/library/topic?id=")
    var html = "";
    var branch_id = ParentParam("id");
    if (branch_id == null) {
	branch_id = "";
	document.getElementById('link_home').className += 'current';
    }
    for (var i in results) {
	var category_id = results[i][0];
	var category_text = results[i][1];
	var category_topics = results[i][2];
	html += "<dt>" + category_text + "</dt>\n";
	html += "<dd><ul>\n";
	for (var j in category_topics) {
	    results[i][2].sort(LabelSorter);
	    var topic_id = results[i][2][j][0].substr(6);
	    var topic_text = results[i][2][j][1];
	    var topic_class = (topic_id == branch_id) ?
		" class=\"current\"" : "";
	    html += "<li" + topic_class +
		"><a href=\"" + url_base + topic_id +
		"\" target=\"_top\">" + topic_text +
		"</a></li>\n"
	}
	html += "</ul></dd>\n"
    }
    if (results.length == 0) {
	html = "<em>No topics found.</em>";
    } else {
	html = "<dl>\n" + html + "</dl>";
    }
    document.getElementById('topic_list').innerHTML = html;
    gadgets.window.adjustHeight();
}
